package com.sas.web.panel.stocks;

import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByBorder;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.sas.domain.Stock;
import com.sas.repository.StockRepository;
import com.sas.web.dataProvider.SortableStockDataProvider;
import com.sas.web.panel.articles.ArticlesListPanel;



@SuppressWarnings("serial")
public class StocksShortListPanel extends Panel {
	
	@SpringBean
	private StockRepository stockRepository;

	
	public StocksShortListPanel(String id, ArticlesListPanel articlesListPanel) {
		super(id);
		
		//SortableGenericDataProvider dp = new SortableGenericDataProvider(vendorRepository, "name");
		//SortableVendorDataProvider dp = new SortableVendorDataProvider(vendorRepository, "name", articlesListPanel);
		SortableStockDataProvider<Stock> dp  = new SortableStockDataProvider<Stock>(stockRepository, "place", articlesListPanel);
		
		final DataView<Stock> dataView = new DataView<Stock>("stocksList", dp) {

			@Override
			protected void populateItem(final Item<Stock> item) {
				Stock stock = item.getModelObject();
				item.add(new Label("code", stock.getId().toString()));
				item.add(new Label("place", stock.getPlace()));
				item.add(new Label("buyPrice", stock.getBuyPrice().toString()));
			}
			
		};
		
		add(new OrderByBorder("orderByCode", "code", dp){
            @Override
            protected void onSortChanged()
            {
                dataView.setCurrentPage(0);
            }
        });
		
		add(new OrderByBorder("orderByPlace", "place", dp){
            @Override
            protected void onSortChanged()
            {
                dataView.setCurrentPage(0);
            }
        });
		
		add(new OrderByBorder("orderByBuyPrice", "buyPrice", dp){
            @Override
            protected void onSortChanged()
            {
                dataView.setCurrentPage(0);
            }
        });
   
		
		add(dataView);
        add(new PagingNavigator("navigator", dataView));
		
	}

}
